package com.sprucetec.live.mcq.listener;


import com.alibaba.rocketmq.common.message.MessageExt;
import com.sprucetec.live.constants.MqConstant;
import com.sprucetec.live.mcq.process.LiveChatMsgProcess;
import com.sprucetec.mcq.consumer.MessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 视频聊天消息消费者
 *
 * @author kenny
 */
@Slf4j
@Component("liveChatListener")
public class LiveChatListener implements MessageListener {

    @Autowired
    private LiveChatMsgProcess liveChatMsgProcess;

    @Override
    public void onMessage(List<MessageExt> list) throws Exception {
        for (MessageExt message : list) {
            String messageBody = new String(message.getBody());
            if (MqConstant.ChatMq.TAG.equals(message.getTags())) { // 异步同步聊天数据
                liveChatMsgProcess.processChatMessage(messageBody);
            } else if (MqConstant.VideoDataMq.TAG.equals(message.getTags())) { // 用户打开详情页
                liveChatMsgProcess.processVideoDataMessage(messageBody);
            }
        }
    }

}
